﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Text;
using smforj.common.service;
using smforj.common.model;
using smforj.common.dao;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest2
    {
        [TestMethod] 
        public void TestSaveFittings()
        {
            IFittingDao service = new FittingSqliteDaoImpl();
            System.Collections.Generic.List<Collocation> list = new System.Collections.Generic.List<Collocation>();
            list.Add(new Collocation()
            {
                ID= Guid.NewGuid().ToString(),
                Name = "阿里上衣1", 
                image = @"F:\vs\favor\MonitorEquipment\MonitorEquipmentFrm\bin\Debug\images\coat1.jpg",
                Order = 1,
                Type = "上衣",
                Loaction = "城北回龙观店",
                RFID = "300833B2DDD9014000000001"
            });
            list.Add(new Collocation()
            {
                ID = Guid.NewGuid().ToString(),
                Name = "阿里上衣2",
                image = @"F:\vs\favor\MonitorEquipment\MonitorEquipmentFrm\bin\Debug\images\coat2.jpg",
                Order = 1,
                Type = "上衣",
                Loaction = "城北回龙观店",
                RFID = "300833B2DDD9014000000002"
            });
            list.Add(new Collocation()
            {
                ID = Guid.NewGuid().ToString(),
                Name = "阿里裤子1",
                image = @"F:\vs\favor\MonitorEquipment\MonitorEquipmentFrm\bin\Debug\images\pants1.jpg",
                Order = 2,
                Type = "裤子",
                Loaction = "城北回龙观店",
                RFID = "300833B2DDD9014000000003"
            });
            list.Add(new Collocation()
            {
                ID = Guid.NewGuid().ToString(),
                Name = "阿里裤子2",
                image = @"F:\vs\favor\MonitorEquipment\MonitorEquipmentFrm\bin\Debug\images\pants2.jpg",
                Order = 2,
                Type = "裤子",
                Loaction = "城北回龙观店",
                RFID = "300833B2DDD9014000000004"
            });
            list.Add(new Collocation()
            {
                ID = Guid.NewGuid().ToString(),
                Name = "阿里靴子",
                image = @"F:\vs\favor\MonitorEquipment\MonitorEquipmentFrm\bin\Debug\images\Shoes1.jpg",
                Order = 3,
                Type = "鞋子",
                Loaction = "城北回龙观店",
                RFID = "300833B2DDD9014000000003"
            });
            list.Add(new Collocation()
            {
                ID = Guid.NewGuid().ToString(),
                Name = "阿里靴子2",
                image = @"F:\vs\favor\MonitorEquipment\MonitorEquipmentFrm\bin\Debug\images\Shoes2.jpg",
                Order = 3,
                Type = "鞋子",
                Loaction = "城北回龙观店",
                RFID = "300833B2DDD9014000000002"
            });

            service.SaveCollocationBatch(list);
        }
        [TestMethod] 
        [Ignore]
        public void TestWardRobe()
        {
            IWardRobeDao service = new WardRobeSqliteDaoImpl();
            System.Collections.Generic.List<PreferenceShow> list = new System.Collections.Generic.List<PreferenceShow>();
            list.Add(new PreferenceShow() { id=Guid.NewGuid().ToString(), Count=2, holdtime=30, 
                 image=@"F:\vs\favor\MonitorEquipment\MonitorEquipmentFrm\bin\Debug\images\coat1.jpg",
                                            remark = "yrd",
                                            type = "上衣",
                                            location = "城北回龙观店",
                                            rfid = "300833B2DDD9014000000001"
            });
            list.Add(new PreferenceShow()
            {
                id = Guid.NewGuid().ToString(),
                Count = 2,
                holdtime = 30,
                image = @"F:\vs\favor\MonitorEquipment\MonitorEquipmentFrm\bin\Debug\images\coat2.jpg",
                remark = "yrd",
                type = "上衣",
                location = "城北回龙观店",
                rfid = "300833B2DDD9014000000002"
            }); 
            list.Add(new PreferenceShow()
            {
                id = Guid.NewGuid().ToString(),
                Count = 2,
                holdtime = 30,
                image = @"F:\vs\favor\MonitorEquipment\MonitorEquipmentFrm\bin\Debug\images\coat3.jpg",
                remark = "yrd",
                type = "上衣",
                location = "城北回龙观店",
                rfid = "300833B2DDD9014000000003"
            }); list.Add(new PreferenceShow()
            {
                id = Guid.NewGuid().ToString(),
                Count = 2,
                holdtime = 30,
                image = @"F:\vs\favor\MonitorEquipment\MonitorEquipmentFrm\bin\Debug\images\coat2.jpg",
                remark = "yrd",
                type = "上衣",
                location = "城北回龙观店",
                rfid = "300833B2DDD9014000000003"
            }); list.Add(new PreferenceShow()
            {
                id = Guid.NewGuid().ToString(),
                Count = 2,
                holdtime = 30,
                image = @"F:\vs\favor\MonitorEquipment\MonitorEquipmentFrm\bin\Debug\images\coat4.jpg",
                remark = "yrd",
                type = "上衣",
                location = "城北回龙观店",
                rfid = "300833B2DDD9014000000004"
            }); list.Add(new PreferenceShow()
            {
                id = Guid.NewGuid().ToString(),
                Count = 2,
                holdtime = 30,
                image = @"F:\vs\favor\MonitorEquipment\MonitorEquipmentFrm\bin\Debug\images\coat5.jpg",
                remark = "yrd",
                type = "上衣",
                location = "城北回龙观店",
                rfid = "300833B2DDD9014000000005"
            });  

            service.SavePreferenceShowBatch(list); 
        }

        [TestMethod]
        [Ignore]
        public void UUIDTest()
        {
            String str = Guid.NewGuid().ToString();
            Console.WriteLine(str);
        }

        /// <summary>
        /// SC->ACS图书信息
        /// </summary>
        /// <param name="bookid">图书条码或RFID</param>
        /// <returns></returns>
        public static string BookInfoMsg(string bookid)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("17"); // 17号命令
            sb.Append(DateTime.Now.ToString("yyyyMMdd    HHmmss")); //执行时间，注意有4个空格
            sb.Append("AO107"); // SC机构标识044120
            sb.Append("|");
            sb.Append("AB" + bookid.ToUpper().Trim()); // 图书id（条码）
            sb.Append("|");
            sb.Append("AC"); // 终端密码，此处不提供
            sb.Append("|");
            sb.Append("AY1AZ"); // 准备校验码
            string text1 = sb.ToString().Trim();
            if (1 != GetChecksum(ref text1))
            {
                return null;
            }
            return text1;
        }
        /// <summary>
        /// 校验码
        /// </summary>
        /// <param name="szCMD">AZ及之前的命令</param>
        /// <returns>生成的校验码</returns>
        private static int GetChecksum(ref string szCMD)
        {
            try
            {
                ushort num1 = 0;
                int num2 = szCMD.Length;
                string text2 = szCMD;
                for (int num5 = 0; num5 < text2.Length; num5++)
                {
                    ushort num3 = text2[num5];
                    num1 = (ushort)(num1 + num3);
                }
                num1 = (ushort)(~num1 + 1);
                string text1 = num1.ToString("X").PadLeft(4, '0');
                szCMD = szCMD + text1;
                // szCMD = szCMD + Environment.NewLine;
            }
            catch (Exception)
            {
                return 0;
            }
            return 1;
        }

    }
}
